// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#pragma once

#include <pollux/common/file/file_systems.h>

namespace kumo::pollux::filesystems {

/// Implementation of the ABS (Azure Blob Storage) filesystem and file
/// interface. We provide a registration method for reading and writing files so
/// that the appropriate type of file can be constructed based on a filename.
/// The supported schema is `abfs(s)://` to align with the valid scheme
/// identifiers used in the Hadoop Filesystem ABFS driver when integrating with
/// Azure Blob Storage. One key difference here is that the ABFS Hadoop client
/// driver always uses Transport Layer Security (TLS) regardless of the
/// authentication method chosen when using the `abfss` schema, but not mandated
/// when using the `abfs` schema. In our implementation, we always use the HTTPS
/// protocol, regardless of whether the schema is `abfs://` or `abfss://`. The
/// legacy wabs(s):// schema is not supported as it has been deprecated already
/// by Azure Storage team. Reference document -
/// https://learn.microsoft.com/en-us/azure/databricks/storage/azure-storage.
class AbfsFileSystem : public FileSystem {
 public:
  explicit AbfsFileSystem(std::shared_ptr<const config::ConfigBase> config);

  std::string name() const override;

  std::unique_ptr<ReadFile> openFileForRead(
      std::string_view path,
      const FileOptions& options = {}) override;

  std::unique_ptr<WriteFile> openFileForWrite(
      std::string_view path,
      const FileOptions& options = {}) override;

  void rename(
      std::string_view path,
      std::string_view newPath,
      bool overWrite = false) override {
    POLLUX_UNSUPPORTED("rename for abfs not implemented");
  }

  void remove(std::string_view path) override {
    POLLUX_UNSUPPORTED("remove for abfs not implemented");
  }

  bool exists(std::string_view path) override {
    POLLUX_UNSUPPORTED("exists for abfs not implemented");
  }

  std::vector<std::string> list(std::string_view path) override {
    POLLUX_UNSUPPORTED("list for abfs not implemented");
  }

  void mkdir(
      std::string_view path,
      const filesystems::DirectoryOptions& options = {}) override {
    POLLUX_UNSUPPORTED("mkdir for abfs not implemented");
  }

  void rmdir(std::string_view path) override {
    POLLUX_UNSUPPORTED("rmdir for abfs not implemented");
  }
};

void registerAbfsFileSystem();
} // namespace kumo::pollux::filesystems
